package goodAPi

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/smartwalle/alipay/v3"
	"github.com/smartwalle/xid"
	"net/http"
	"serviceApi/global"
	"serviceApi/service/goodSrv"
)

func GoodList(c *gin.Context) {
	list, err := goodSrv.GoodList()
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{
			"code":    "-1",
			"message": err.Error(),
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code":    "200",
		"data":    list,
		"message": "商品列表展示成功",
	})
}
func AliPay(c *gin.Context) {
	var tradeNo = fmt.Sprintf("%d", xid.Next())
	var p = alipay.TradePagePay{}
	//p.NotifyURL = kServerDomain + "/alipay/notify"
	p.ReturnURL = "www.baidu.com"
	p.Subject = "支付测试:" + tradeNo
	p.OutTradeNo = tradeNo
	p.TotalAmount = "100.00"
	p.ProductCode = "FAST_INSTANT_TRADE_PAY"
	url, err := global.AliPayClient.TradePagePay(p)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{
			"code":    "-1",
			"message": "支付宝支付失败",
		})
	}

	c.JSON(http.StatusOK, gin.H{
		"code":    "200",
		"data":    url.String(),
		"message": "支付宝支付成功",
	})
}
